<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use common\helpers\StringHelper;
use common\widgets\ueditor\Ueditor;

$this->title = 'News Flash';
?>
<div class="blog-index">

    <p class="text-right">
        <?= Html::a('新建', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php
    echo \yii\bootstrap\Tabs::widget([
        'items' => [
            [
                'label' => '全部',
                'url' => '/newsflash/index?active=all',
                'active' => $active == 'all' ? true : false
            ],
            [
                'label' => '草稿',
                'url' => '/newsflash/index?active=draft',
                'active' => $active == 'draft' ? true : false
            ],
            [
                'label' => '已发布/已定时',
                'url' => '/newsflash/index?active=published',
                'active' => $active == 'published' ? true : false
            ],
            [
                'label' => '回收站',
                'url' => '/newsflash/index?active=recycle',
                'active' => $active == 'recycle' ? true : false
            ],
        ],
    ]);
    ?>
    <?= GridView::widget([
        'responsiveWrap' => false,
        'dataProvider' => $dataProvider,
        'columns' => [
            'id',
            [
                'attribute' => 'title',
                'format'=>'raw',
                'value' => function ($model) {
                    return StringHelper::truncateMsg($model->title, 35);  //显示省略号
                }
            ],
            'ptime',
            [
                'attribute' => 'status',
                'format'=>'raw',
                'value' => function ($model) {
                    $status = array('0' => '发布中', '1' => '已删除', '2' => '草稿','3' => '定时中');
                    return  $status[$model->status];
                }
            ],
            [
                'attribute' => 'mtime',
                'format'=>'raw',
                'value' => function ($model) {
                    return  date('Y-m-d H:i:s',$model->mtime);
                }
            ],
            [
                'attribute' => 'ctime',
                'format'=>'raw',
                'value' => function ($model) {
                    return  date('Y-m-d H:i:s',$model->mtime);
                }
            ],
            [
                'class' => 'kartik\grid\ActionColumn',
                'template' => '{view}{update}{delete}',
                'buttons' => [
                    'view' => function ($url, $model) {
                        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>查看', $url, [
                            'title' => Yii::t('yii', 'View'),
                            'class' => 'btn btn-xs btn-default'
                        ]);
                    },
                    'update' => function ($url, $model) {
                        return Html::a('<span class=" glyphicon glyphicon-pencil"></span>更新', $url, [
                            'title' => Yii::t('yii', 'Update'),
                            'class' => 'btn btn-xs btn-primary'
                        ]);
                    },
                    'delete' => function ($url, $model) {
                        return Html::a('<span class=" glyphicon glyphicon-pencil"></span>删除', $url, [
                            'title' => Yii::t('yii', 'Delete'),
                            'class' => 'btn btn-xs btn-primary'
                        ]);
                    }
                ]
            ],
        ],
    ]); ?>

</div>
